package io.kiki.sba.registry.server.metadata.remoting.handler;

import io.kiki.sba.registry.api.Channel;
import io.kiki.sba.registry.common.model.slot.GetSlotsStatusRequest;
import io.kiki.sba.registry.common.model.slot.SlotsStatusResponse;
import io.kiki.sba.registry.server.metadata.MetadataLeaderService;
import io.kiki.sba.registry.server.metadata.slot.status.SlotsStatusService;
import org.springframework.beans.factory.annotation.Autowired;


public class GetSlotsStatusRequestHandler extends BaseMetaServerHandler<GetSlotsStatusRequest> {

    @Autowired
    SlotsStatusService SlotsStatusService;

    @Autowired
    MetadataLeaderService metadataLeaderService;

    @Override
    public Object doHandle(Channel channel, GetSlotsStatusRequest request) {

        if (!metadataLeaderService.amIStableAsLeader()) {
            return null;
        }

        SlotsStatusResponse SlotsStatus = SlotsStatusService.getSlotsStatus();
        return SlotsStatus;
    }

    @Override
    public Class interest() {
        return GetSlotsStatusRequest.class;
    }
}
